home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / p063b9s.zip / UNIT / FUNCREQ.PAS < prev    next >
Pascal/Delphi Source File  |  1996-04-28  |  10KB  |  281 lines

  1. UNIT FuncReq;
  2. {╔══════════════════════════════════════════════════════════════════════════╗}
  3. {║ Function request engine                       Last changed: 28.04.96  SA ║}
  4. {║                                                                          ║}
  5. {║                         (C) Copyright 1989-96 by                         ║}
  6. {║       Dan Wulff, Jens Sandalgaard, Steen Christensen & S¢ren Ager        ║}
  7. {║                                                                          ║}
  8. {║ This source may not be given to anybody, without the written permission  ║}
  9. {║ from The Portal Team.                                                    ║}
  10. {╚══════════════════════════════════════════════════════════════════════════╝}
  11. {$I POPDEFS.INC}
  12.  
  13. INTERFACE
  14.  
  15. USES Use32;
  16.  
  17. PROCEDURE ParseRequest;
  18.  
  19. IMPLEMENTATION
  20.  
  21. USES Dos, OpDate, OpDos, OpString, OpRoot,
  22.      StrUtil, Globals, FileUtil, MailUtil, Util, Config, LogFile, OutUtil,
  23.      NetFile, OproUtil, PoPTypes;
  24.  
  25. CONST
  26.   days:S31='   SUN MON TUE WED THU FRI SAT SUN';
  27.  
  28. PROCEDURE execute_command(s: string);
  29. VAR
  30.   EventFile : TNetFile;
  31.   Event : TEvent;
  32.   i,test,Zone:INTEGER;
  33.   f1,keyword,p1,p2:string;
  34.   evt:s8;
  35.   Adr : TFidoAddress;
  36.  
  37.   PROCEDURE DO_macro(CONST name: s10);
  38.   VAR
  39.     f : TBufTextFile;
  40.     s : String;
  41.   BEGIN
  42.     IF NOT f.Init(Name+'.PFM', SOpenRead, 512) THEN
  43.     BEGIN
  44.       AddLog('!','The MACRO '+name+' could not be found');
  45.     END ELSE
  46.     BEGIN
  47.       AddLog('!','Macro '+name+' Begin');
  48.       while NOT f.eof DO
  49.       BEGIN
  50.         f.ReadLn(s);
  51.         execute_command(s);
  52.       END;
  53.       f.Done;
  54.       addlog('!','Macro '+name+' End');
  55.     END;
  56.   END;
  57.  
  58. BEGIN
  59.   s:=StUpCase(s);
  60.   KeyWord:=NextWord(' ',s);
  61.   IF keyword<>'' THEN
  62.   BEGIN
  63.     IF keyword='DELETE' THEN
  64.     BEGIN
  65.       IF DeleteFile(s) THEN addlog('!',StUpCase(s)+' Deleted') ELSE addlog('!',StUpCase(s)+' NOT deleted');
  66.     END ELSE
  67.       IF (keyword='MOVE') OR (keyword='COPY') THEN
  68.       BEGIN
  69.         f1:=NextWord(' ',s);
  70.         IF copyfile(f1,s,False,(KeyWord='MOVE'))=0 THEN
  71.           IF (Keyword='MOVE') THEN addlog('!', StUpCase(f1)+' Moved to '+s) ELSE
  72.             AddLog('!', StUpCase(f1)+' copied to '+s);
  73.       END ELSE
  74.         IF keyword='SEND' THEN
  75.         BEGIN
  76.           p1:=NextWord(' ',s);
  77.           p2:=NextWord(' ',s);
  78.           IF NOT GetAdressFromStr(p2,Adr) THEN
  79.           BEGIN
  80.             Adr:=Call;
  81.             p2:=Address2Str(Call);
  82.           END;
  83.           IF ExistFile(p1) THEN
  84.           BEGIN
  85.             addlog('!','Sent '+StUpCase(p1)+' to '+p2);
  86.             SendAFile(p1,Adr,'H',STNothing);
  87.           END ELSE
  88.             addlog('!','Could NOT find '+StUpCase(p1)+' for '+p2);
  89.         END ELSE
  90.           IF keyword='POLL' THEN
  91.           BEGIN
  92.             p1:=NextWord(' ',s);
  93.             p2:=COPY(NextWord(' ',s),1,1);
  94.             IF NOT (p2[1] IN ['C','I','N','D']) THEN p2:='C';
  95.             IF GetAdressFromStr(p1,Adr) THEN
  96.             BEGIN
  97.               addlog('!','Poll requested for '+s);
  98.               MakeAPoll(Adr,p2[1]);
  99.             END;
  100.           END ELSE
  101.             IF keyword='DOS' THEN
  102.             BEGIN
  103.               addlog('!','Executing '+StUpCase(s));
  104.               ExecDos(s,TRUE,NoExecDosProc);
  105.             END ELSE
  106.               IF keyword='SHUTDOWN' THEN
  107.               BEGIN
  108.                 addlog('!','Shutting down '+cfg.system);
  109.                 FinishPortal;
  110.                 Halt;
  111.               END ELSE
  112.                 IF keyword='EVENT' THEN
  113.                 BEGIN
  114.                   evt:=NextWord(' ',s);
  115.                   VAL(evt,i,test);
  116.                   IF (test=0) AND (i>0) THEN
  117.                   BEGIN
  118.                     EventFile.Open(StartPath+PoPEventFileName,SizeOf(TEvent),TRUE);
  119.                     EventFile.GetRec(Event,i-1,Keep,Wait);
  120.                     WITH Event DO
  121.                     BEGIN
  122.                       REPEAT
  123.                         p2:=NextWord(' ',s);
  124.                         IF p2='ENABLE' THEN
  125.                         BEGIN
  126.                           Active:=Active OR 1;
  127.                           addlog('!','Enabling event #'+evt);
  128.                         END ELSE
  129.                           IF p2='DISABLE' THEN
  130.                           BEGIN
  131.                             Active:=Active AND 254;
  132.                             addlog('!','Disabling event #'+evt);
  133.                           END ELSE
  134.                             IF p2='START' THEN
  135.                             BEGIN
  136.                               p1:=NextWord(' ',s);
  137.                               Start:=TimeStringToTime('HH:MM',p1);
  138.                               addlog('!','Setting event #'+evt+' to start at '+p1);
  139.                             END ELSE
  140.                               IF (p2='RUN') OR (p2='NORUN') THEN
  141.                               BEGIN
  142.                                 p1:=NextWord(' ',s);
  143.                                 IF p1='ALL' THEN
  144.                                 BEGIN
  145.                                   test:=127;
  146.                                 END ELSE
  147.                                 BEGIN
  148.                                   test:=POS(p1,days) DIV 4;
  149.                                   IF test>0 THEN
  150.                                   BEGIN
  151.                                     DEC(test);
  152.                                     zone:=1 SHL test;
  153.                                   END;
  154.                                 END;
  155.                                 IF p2='RUN' THEN
  156.                                 BEGIN
  157.                                   Active:=Active OR zone;
  158.                                   addlog('!','Setting event #'+evt+' to run on '+p1);
  159.                                 END ELSE
  160.                                 BEGIN
  161.                                   Active:=Active AND (255-zone);
  162.                                   addlog('!','Setting event #'+evt+' NOT to run on '+p1);
  163.                                 END;
  164.                               END;
  165.                               IF p2='MAXBAD' THEN
  166.                               BEGIN
  167.                                 p1:=NextWord(' ',s);
  168.                                 VAL(p1,zone,test);
  169.                                 IF test=0 THEN
  170.                                 BEGIN
  171.                                   addlog('!','Changing Max. bad of event #'+evt+' to '+p1);
  172.                                   Tries.Bad:=zone;
  173.                                 END ELSE
  174.                                   addlog('!','Invalid number "'+p1+'"');
  175.                               END ELSE
  176.                                 IF p2='MAXNO' THEN
  177.                                 BEGIN
  178.                                   p1:=NextWord(' ',s);
  179.                                   VAL(p1,zone,test);
  180.                                   IF test=0 THEN
  181.                                   BEGIN
  182.                                     addlog('!','Changing Max. No connect of event #'+evt+' to '+p1);
  183.                                     Tries.Busy:=zone;
  184.                                   END ELSE
  185.                                     addlog('!','Invalid number "'+p1+'"');
  186.                                 END ELSE
  187.                                   IF p2='POLLEXIT' THEN
  188.                                   BEGIN
  189.                                     p1:=NextWord(' ',s);
  190.                                     VAL(p1,zone,test);
  191.                                     IF test=0 THEN
  192.                                     BEGIN
  193.                                       addlog('!','Changing Pollexit of event #'+evt+' to '+p1);
  194.                                       PollExit:=zone;
  195.                                     END ELSE
  196.                                       addlog('!','Invalid number "'+p1+'"');
  197.                                   END ELSE
  198.                                     IF p2='MAILEXIT' THEN
  199.                                     BEGIN
  200.                                       p1:=NextWord(' ',s);
  201.                                       VAL(p1,zone,test);
  202.                                       IF test=0 THEN
  203.                                       BEGIN
  204.                                         addlog('!','Changing Mailexit of event #'+evt+' to '+p1);
  205.                                         MailExit:=zone;
  206.                                       END ELSE
  207.                                         addlog('!','Invalid number "'+p1+'"');
  208.                                     END;
  209.                       UNTIL s='';
  210.                     END;
  211.                     EventFile.PutRec(Event,i-1);
  212.                     EventFile.Close;
  213.                   END ELSE
  214.                     addlog('!','Invalid event number "'+p1+'"');
  215.                 END ELSE
  216.                   IF keyword='MACRO' THEN
  217.                   BEGIN
  218.                     DO_macro(s);
  219.                   END ELSE
  220.                   BEGIN
  221.                     addlog('!','Unknown command "'+keyword+'"');
  222.       END;
  223.       SaveConfiguration;
  224.   END;
  225. END;
  226.  
  227. PROCEDURE ParseRequest;
  228. LABEL
  229.   Slut;
  230. VAR
  231.   f : PBufTextFile;
  232.   s : STRING;
  233.   pwdchecked:BOOLEAN;
  234.   sr:SearchRec;
  235. BEGIN
  236. {$IFNDEF PoPLite}
  237.   FindFirst(Cfg.Inbound[GlobNodeStat]+'*.PFR',AnyFile,sr);
  238.   WHILE DOSERROR=0 DO
  239.   BEGIN
  240.     AddLog('!','Processing function request file "'+Sr.Name+'"');
  241.     IF Cfg.FuncReqPwd<>'' THEN
  242.     BEGIN
  243.       PwdChecked:=FALSE;
  244.       New(f, Init(Cfg.Inbound[GlobNodeStat]+Sr.Name, SOpenRead+ShareDenyW, 1024));
  245.       IF f<>NIL THEN
  246.       BEGIN
  247.         WHILE NOT f^.EOF DO
  248.         BEGIN
  249.           f^.ReadLn(s);
  250.           s:=s+' ';
  251.           Replace(s,'  ',' ',0);
  252.           IF NOT PwdChecked THEN
  253.           BEGIN
  254.             PwdChecked:=TRUE;
  255.             IF StUpCase(NextWord(' ',s))='PASSWORD' THEN
  256.             BEGIN
  257.               s:=NextWord(' ',s);
  258.               IF StUpCase(s)<>Cfg.FuncReqPwd THEN
  259.               BEGIN
  260.                 AddLog('!','Invalid password "'+s+'"');
  261.                 GOTO Slut;
  262.               END;
  263.             END;
  264.           END ELSE
  265.             IF COPY(s,1,1)<>^A THEN Execute_Command(s);
  266.         END;
  267.   Slut:
  268.         Dispose(f, Done);
  269.         AddLog('!','Finished processing "'+sr.name+'"');
  270.       END ELSE
  271.         AddLog('!', 'Not enough memory to open: '+Sr.Name);
  272.     END;
  273.     DeleteFile(Cfg.Inbound[GlobNodeStat]+Sr.Name);
  274.     FindNext(sr);
  275.   END;
  276.   FindClose(sr);
  277. {$ENDIF}
  278. END;
  279.  
  280. END.
  281.